﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XiaoYuStock.Core;
using XiaoYuStock.WebApp.Helpers;
namespace XiaoYuStock.WebApp.Controllers
{
    public class AuthController : Controller
    {
 
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(string username, string password, string verifycode)
        {

            if (username.ToLower() == "admin" && password.ToLower() == "111111")
            {
                LoginUser user = new LoginUser();
                user.UserName = username;
                user.Password = password;
                LoginUserManager.SignLoginUser(user);
                var referUrl =string.Empty;
                if (this.Request.QueryString["rurl"] != null)
                    referUrl = this.Request.QueryString["rurl"].ToString();
                if (!string.IsNullOrWhiteSpace(referUrl))
                    return Redirect(referUrl);
                else
                  return RedirectToAction("Index","Home");
            }
            else
            {
                ModelState.AddModelError("error", "用户名或密码错误");
                return View();
            }
            return View();
        }

        public ActionResult Logout()
        {
            LoginUserManager.Logout(); 
            return RedirectToAction("Login");
        }

        public virtual ActionResult VerifyImage()
        {
            var validateCodeType = new ValidateCode_Style10();
            string code = "6666";
            byte[] bytes = validateCodeType.CreateImage(out code);
           // this.CookieContext.VerifyCodeGuid = VerifyCodeHelper.SaveVerifyCode(code);

            return File(bytes, @"image/jpeg");
        }

    }
}
